﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using C1.C1Zip;


namespace NRainel.Data.Compress
{
    /*
     数据压缩
     */
    public class CompressData
    {
        public static byte[] CompressString(string data)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (C1ZStreamWriter sw = new C1ZStreamWriter(ms))
                {
                    using (StreamWriter writer = new StreamWriter(sw))
                    {
                        writer.Write(data);
                        writer.Flush();
                        return ms.ToArray();
                    }
                }
            }
        }
        public static string DecompressString(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                using (C1ZStreamReader sr = new C1ZStreamReader(ms))
                {
                    using (StreamReader reader = new StreamReader(sr))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }
    }
}
